package it.unibo.convoycruisecontrol.chiefboatsubsystem.test.unit;

import static org.junit.Assert.*;
import it.unibo.convoycruisecontrol.chiefboatsubsystem.IFlagDisplay;

import org.junit.Before;
import org.junit.Test;

public abstract class FlagDisplayTestCase {
	
	public abstract IFlagDisplay createConcreteFlagDisplay(int numberOfBoats);
	int numberOfBoats1 = 5;
	int numberOfBoats2 = 3;
	IFlagDisplay flagDisplayx5;
	IFlagDisplay flagDisplayx3;
	
	@Before
	public void beforeClass()
	{
		flagDisplayx5 = createConcreteFlagDisplay(numberOfBoats1);
		flagDisplayx3 = createConcreteFlagDisplay(numberOfBoats2);
	}

	@Test
	public void invariant() 
	{
		flagDisplayx5.setFlag(0);
		flagDisplayx5.setFlag(1);
		flagDisplayx5.setFlag(2);
		
		boolean[] expectedflags = {true, true, true, false, false};
		Boolean[] actualFlags = flagDisplayx5.getDisplayedFlags().toArray(new Boolean[0]);
		for(int i=0; i < expectedflags.length; i++)
		{
			assertEquals(expectedflags[i], actualFlags[i]);
		}
		
		flagDisplayx5.clearFlag(0);
		flagDisplayx5.clearFlag(1);
		flagDisplayx5.clearFlag(2);
		
		boolean[] expectedflags2 = {false, false, false, false, false};
		actualFlags = flagDisplayx5.getDisplayedFlags().toArray(new Boolean[0]);
		for(int i=0; i < expectedflags.length; i++)
		{
			assertEquals(expectedflags2[i], actualFlags[i]);
		}
		
	}
	
	@Test(expected=IllegalArgumentException.class)
	public void testCreation() 
	{
		createConcreteFlagDisplay(-6);
	}
	
	@Test
	public void testCreation2() 
	{
		assertEquals(numberOfBoats1, flagDisplayx5.getDisplayedFlags().size());
		assertEquals(numberOfBoats2, flagDisplayx3.getDisplayedFlags().size());
	}
	
	@Test(expected=IndexOutOfBoundsException.class)
	public void testIndexBoundsSet() 
	{
		flagDisplayx5.setFlag(90);
	}
	
	@Test(expected=IndexOutOfBoundsException.class)
	public void testIndexBoundsClear() 
	{
		flagDisplayx5.clearFlag(90);
	}

}
